package com.example.springcloud.service.Impl;

import com.example.springcloud.service.ImessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.Date;

/*
 * @Author: hanj
 * @Email: hanj.cn@outlook.com
 * @Date: 2022/1/3 14:31
 */
@Slf4j
@EnableBinding(Source.class) // 定义消息的推送管道
public class ImessageServiceImpl implements ImessageService {

    @Resource
    private MessageChannel output;

    @Override

    public void sendMessage() {

        String date = String.valueOf(new Date());
        log.warn("send message : " + date);
        output.send(MessageBuilder.withPayload(date).build());
    }

}
